package com.lqq.chapter04.ArrayListDemo;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.Vector;

/**
 * @Author lqq677
 * @Date 2021/8/10 15:40
 * @Description 解决ArrayList线程不安全方案一：Vector
 */
public class VectorTest {
    public static void main(String[] args) {
        List<String> list = new Vector<>();
        for (int i = 0; i < 30; i++) {//多个线程同时对集合进行修改
            new Thread(() ->{
                //向集合添加内容
                list.add(UUID.randomUUID().toString().substring(0,8));
                //从集合里获取内容
                System.out.println(list);
            }, String.valueOf(i)).start();
        }
    }
}
